package com.prize.service.impl;

import com.prize.dtos.ResponseResult;
import com.prize.mapper.SysOplogMapper;
import com.prize.pojo.SysOplog;
import com.prize.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @descriptions: 日志管理
 * @author: yunqiang
 * @date: 2022/5/28 18:50
 */
@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysOplogMapper sysOplogMapper;

    /**
     * 日志列表
     * @param username 用户名
     * @param opContent 操作
     * @param ip ip地址
     * @param pageSize 页数
     * @param pageNow 当前页
     * @return
     */
    @Override
    public ResponseResult getLods(String username, String opContent, String ip, int pageSize, int pageNow) {
        if (pageNow > 0){
            pageNow  =(pageNow - 1)*pageSize;
        }else{
            pageNow = 0;
        }
        long total = sysOplogMapper.getLodsCount(username,opContent,ip);
        List<SysOplog> sysOplogs = sysOplogMapper.getLods(username,opContent,ip,pageNow,pageSize);
        if(CollectionUtils.isEmpty(sysOplogs)){
            return ResponseResult.noResult();
        }
        return ResponseResult.success(total,sysOplogs);
    }
}
